import { AllHTMLAttributes, createElement, type FC } from 'react';
import classNames from 'classnames';

import { listDescriptionDefaultProps } from './defaultProps';
import type { ListDescriptionOptions } from './type';

export interface ListDescriptionProps extends ListDescriptionOptions, Omit<AllHTMLAttributes<HTMLElement>, 'as'> {}

const ListDescription: FC<ListDescriptionProps> = (props) => {
  const { className, as, children, forwardedRef, ...listDescriptionProps } = props;

  return createElement(
    as!,
    { ref: forwardedRef, className: classNames('description', className), ...listDescriptionProps },
    children,
  );
};

ListDescription.displayName = 'ListDescription';
ListDescription.defaultProps = listDescriptionDefaultProps;

export default ListDescription;
